package com.genius.reservation.common.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.genius.reservation.driver.service.IDriverInformationService;
import com.genius.reservation.receiveManager.service.IReceiveManagerInformationService;
import com.genius.reservation.receiver.service.IReceiverInformationService;
import com.genius.reservation.supplier.service.ISupplierService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BaseConsumer {
    @Autowired
    IReceiveManagerInformationService receiveManagerInformationService;

    @Autowired
    IDriverInformationService driverService;

    @Autowired
    IReceiverInformationService receiverService;

    @Autowired
    ISupplierService supplierService;


    //收货总管监听
    @RabbitListener(queues = RabbitConfig.RECEIVE_MANAGER)
    public void receiveManagerConsumer(String msg){
        JSONObject jsonObject = JSONObject.parseObject(msg);
        RabbitMessageEntity rabbitMessageEntity = jsonObject.toJavaObject(RabbitMessageEntity.class);
        receiveManagerInformationService.newMessage(rabbitMessageEntity);
    }

//    @RabbitListener(queues = RabbitConfig.EDIT_RESERVATION)
//    public void editReservation(JSONObject msg){
//        receiveManagerInformationService.newMessage(msg);
//    }
//
//    @RabbitListener(queues = RabbitConfig.CANCEL_RESERVATION)
//    public void cancelReservation(JSONObject msg){
//        receiveManagerInformationService.newMessage(msg);
//    }
//
//
//    @RabbitListener(queues = RabbitConfig.FINISH_RESERVATION)
//    public void finishReservation(JSONObject msg){
//        driverService.newMessage(msg);
//    }

    //司机监听
    @RabbitListener(queues = RabbitConfig.DRIVER)

    public void driverConsumer(String msg){
        JSONObject jsonObject = JSONObject.parseObject(msg);
        RabbitMessageEntity rabbitMessageEntity = jsonObject.toJavaObject(RabbitMessageEntity.class);
//        driverService.newMessage(rabbitMessageEntity);
    }


    //收货员监听
    @RabbitListener(queues = RabbitConfig.RECEIVER)
    public void receiverConsumer(String msg){
        JSONObject jsonObject = JSONObject.parseObject(msg);
        RabbitMessageEntity rabbitMessageEntity = jsonObject.toJavaObject(RabbitMessageEntity.class);
//        receiverService.newMessage(rabbitMessageEntity);
    }


    //供应商监听
    @RabbitListener(queues = RabbitConfig.RECEIVER)
    public void supplierConsumer(String msg){
        JSONObject jsonObject = JSONObject.parseObject(msg);
        RabbitMessageEntity rabbitMessageEntity = jsonObject.toJavaObject(RabbitMessageEntity.class);
        supplierService.newMessage(rabbitMessageEntity);
    }
}
